<template>
	<div class="container">
	  <!-- 搜索框 -->
	  <div class="search-box">
		<div class="search-container">
		  <input
			class="search-input"
			placeholder="输入搜索关键词"
			placeholder-class="placeholder"
			v-model="searchKeyword"
		  />
		  <div class="search-button" @click="onSearch">
			<img class="search-icon" src="./images/search.png" alt="Search" />
		  </div>
		</div>
	  </div>
  
	  <!-- 轮播图 -->
	  <div class="carousel">
		<swiper
		  class="swiper"
		  :indicator-dots="true"
		  :autoplay="true"
		  :interval="5000"
		  :duration="500"
		  @change="onSlideChange"
		>
		  <swiper-item v-for="slide in slides" :key="slide.id">
			<div class="slide">
			  <img class="slide-image" :src="slide.image" alt="Slide" />
			</div>
		  </swiper-item>
		</swiper>
	  </div>
  
	  <!-- 文章列表 -->
	  <div class="article-list">
		<div
		  v-for="article in articles"
		  :key="article.id"
		  class="article-card"
		>
		  <div class="article-title">{{ article.title }}</div>
		  <div class="article-content">
			<img
			  class="article-image"
			  :src="article.image"
			  alt="Article"
			/>
			<div class="article-text-container">
			  <div class="article-description">{{ article.description }}</div>
			  <div class="article-actions">
				<button class="action-button">支持</button>
				<button class="action-button">不支持</button>
			  </div>
			</div>
		  </div>
		</div>
	  </div>
	</div>
  </template>
  
  <script setup>
  import { ref, onMounted } from 'vue';
  
  // 数据
  const slides = ref([
	{
	  id: 1,
	  image: './images/search.png',
	},
	{
	  id: 2,
	  image: './images/search.png',
	},
  ]);
  const articles = ref([
	{
	  id: 1,
	  title: '干货|学会写简历，轻松拿offer',
	  image: './images/search.png',
	  description: '工作计划不会写？这个超赞工具送给你',
	},
	{
	  id: 2,
	  title: '你必须知道的8种产品设计能力提升技巧',
	  image: './images/search.png',
	  description: '来学习！10条你绝对不能打破的交互设计规则',
	},
	{
	  id: 3,
	  title: '最佳产品管理书籍在此，获取职场上升秘籍',
	  image: './images/search.png',
	  description: '干货|学会写简历，轻松拿offer',
	},
  ]);
  const searchKeyword = ref('');
  
  // 生命周期钩子
  onMounted(() => {
	fetchArticlesFromBackend();
  });
  
  // 方法
  const onSearch = () => {
	console.log('搜索关键词:', searchKeyword.value);
	// 这里可以添加搜索逻辑
  };
  
  const onSlideChange = (e) => {
	console.log('当前轮播图索引:', e.detail.current);
  };
  
  const fetchArticlesFromBackend = () => {
	// 模拟从后端获取文章数据
	const mockData = [
	  {
		id: 1,
		title: '干货|学会写简历，轻松拿offer',
		image: './images/search.png',
		description: '工作计划不会写？这个超赞工具送给你',
	  },
	  {
		id: 2,
		title: '你必须知道的8种产品设计能力提升技巧',
		image: './images/search.png',
		description: '来学习！10条你绝对不能打破的交互设计规则',
	  },
	  {
		id: 3,
		title: '最佳产品管理书籍在此，获取职场上升秘籍',
		image: './images/search.png',
		description: '干货|学会写简历，轻松拿offer',
	  },
	];
	articles.value = mockData;
  };
  </script>
  
  <style scoped lang="scss">
  .container {
	width: 100%;
	background-color: #f5f5f5;
	padding: 10px;
	box-sizing: border-box;
  }
  
  /* 搜索框样式 */
  .search-box {
	width: 100%;
	padding: 10px 0;
	background-color: #fff;
	border-radius: 5px;
	margin-bottom: 10px;
  }
  
  .search-container {
	display: flex;
	align-items: center;
	height: 40px;
  }
  
  .search-input {
	width: 90%;
	height: 100%;
	font-size: 14px;
	color: #999;
	background-color: #f5f5f5;
	border-radius: 20px;
	padding: 0 15px;
	box-sizing: border-box;
  }
  
  .search-button {
	width: 10%;
	display: flex;
	justify-content: center;
	align-items: center;
  }
  
  .search-icon {
	width: 24px;
	height: 24px;
  }
  
  .placeholder {
	color: #999;
  }
  
  /* 轮播图样式 */
  .carousel {
	width: 100%;
	height: 150px;
	margin-bottom: 10px;
	border-radius: 5px;
	overflow: hidden;
  }
  
  .swiper {
	width: 100%;
	height: 100%;
  }
  
  .slide {
	width: 100%;
	height: 100%;
  }
  
  .slide-image {
	width: 100%;
	height: 100%;
	object-fit: cover;
  }
  
  /* 文章卡片样式 */
  .article-list {
	width: 100%;
  }
  
  .article-card {
	width: 100%;
	background-color: #fff;
	border-radius: 5px;
	margin-bottom: 10px;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  .article-title {
	padding: 5px;
	font-size: 16px;
	font-weight: bold;
	margin-bottom: 10px;
	color: #333;
  }
  
  .article-content {
	display: flex;
	padding: 0 5px;
  }
  
  .article-image {
	width: 100px;
	height: 100px;
	border-radius: 5px;
	margin-right: 10px;
  }
  
  .article-text-container {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
  }
  
  .article-description {
	font-size: 14px;
	color: #666;
	line-height: 1.4;
	flex: 1;
  }
  
  .article-actions {
	display: flex;
	justify-content: flex-end;
  }
  
  .action-button {
	padding: 5px 10px;
	margin-left: 10px;
	font-size: 12px;
	border: 1px solid #ccc;
	border-radius: 15px;
	background-color: transparent;
	color: #666;
  }
  </style>